//
//  ViewController.m
//  UINavigationController
//
//  Created by dllo on 16/7/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "PushViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//    设置navigationBar的属性
//    title 标题，告诉用户，我这个试图控制器是干啥用的
    self.title = @"我是标题";
    self.navigationItem.title = @"xxxxxx";
//    titleView 标题视图
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"1",@"2",@"3"]];
    segment.frame = CGRectMake(0, 0, 150, 44);
//    标题视图修改x和y对试图本身没影响
    self.navigationItem.titleView = segment;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(comBack:)];
    self.navigationItem .rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
//    self.navigationItem.leftBarButtonItems = @[barButtonItemTitle,barButtonItemSystemItembarItemSystemItem,barButtonItemSystemItem];
    
//    rightBarButtonItems 数组
//    barButtonItems数组中放1-2个item为最优
    
    
    
    
    
    
    segment.selectedSegmentIndex = 1;
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
    self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
//    bar上元素的标题
    self.navigationController.navigationBar.tintColor = [UIColor orangeColor];
    self.navigationController.navigationBar.translucent = NO;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 200, 100);
    
    button.backgroundColor = [UIColor redColor];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationController.navigationBar.translucent = NO;//管理半透明的效果
//    设置为YES时self.view从原点开始
//    NO时从navigationbar下开始
    
    //改变坐标效果，与translucent效果一样
    self.edgesForExtendedLayout = UIRectEdgeNone;
    //   viewControllers
// 获取到navigationController里所有的控制器
//    self.navigationController.viewControllers 
//   返回栈中指定的试图控制器
}

- (void)buttonClicked:(UIButton *)button
{
//    讲视图控制器入栈
    [self.navigationController pushViewController:[[PushViewController alloc]init] animated:YES];
    
}





- (void)add:(UIBarButtonItem *)barButtonItem
{
    
}

- (void)comBack:(UIBarButtonItem *)barButtonItem
{
    NSLog(@"返回");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
